/**
	ProgressIndicator class for showing a tasks progress. Most comonly used in conjunction with the
	{@link LoadView} object to show the loading of LoadView


	@author Chandler McWilliams
	@version 1.0
	@version 2005-06-06

**/

class timber.ui.ProgressIndicator extends MovieClip
{
	
	private var total;
	private var value;
	
	public function ProgressIndicator() {
		hide();
	}
	
/**

	Returns a boolean value if the preloader is determinate.
	
	Determinate preloaders display the amount of content loaded. Indeterminate
	preloaders are just animations that play while the content loads.

	@return (Bool) If the preloader is determinate or not.
**/
	public function isIndeterminate() {
		return true;
	}



/**
	Starts the animation of an indeterminate progress indicator.
	Does nothing for determinate indicators.
**/
	public function startAnimation() {
		show();
		if (isIndeterminate()) this.gotoAndPlay(1);
	}



/**
	Stops the animation of an indeterminate progress indicator.
	Does nothing for determinate indicators.
**/
	public function stopAnimation() {
		hide();
		this.gotoAndStop(1);
	}


/**
	Called when new data is loaded.
	
**/
	public function update() {
		// if determinate, 
		// update by going to the right frame in the animation
		// treats the animation as a scale from 0 to 100%
		if (!this.isIndeterminate()) {
			this.gotoAndStop(Math.round(this._totalframes * value/total));
		}
	}

/**
	Move one step forward
	
**/
	public function step() {
		// if determinate, 
		// update by going to the right frame in the animation
		// treats the animation as a scale from 0 to 100%
		if (!this.isIndeterminate()) {
			setValue(getValue()+1);
			this.gotoAndStop(Math.round(this._totalframes * value/total));
		}
	}

/**
	Sets the total value for the indicator.
	Ignored by indeterminate indicators.
	
	@param newtotal Total value of indicator.
**/
	public function setTotal(newtotal) {
		total = newtotal;
	}

/**
	Gets the total value for the indicator.
	
	@return (Number) Total value of indicator.
**/
	public function getTotal() {
		return total;
	}


/**
	Sets the current value for the indicator.
	Ignored by indeterminate indicators.
	
	@param newvalue Current value of indicator.
**/
	public function setValue(newvalue) {
		value = newvalue;
	}

/**
	Gets the current value for the indicator.
	
	@return (Number) Current value of indicator.
**/
	public function getValue() {
		return value;
	}

/**
	Gets the percentage complete for the indicator.
	
	@return (Number) Percentage complete of indicator.
**/
	private function getPercentage() {
		return 100*value/total;
	}

/**
	Displays the progress bar. Normally used for determinate indicators, indeterminate indicators
	show/hide themselves automatically.
**/
	public function show() {
		this._visible = true;
	}

/**
	hides the progress bar. Normally used for determinate indicators, indeterminate indicators
	show/hide themselves automatically.
**/
	public function hide() {
		this._visible = false;
	}

	
}